home *** CD-ROM | disk | FTP | other *** search
- Path: yama.mcc.ac.uk!rmplc!news
- From: tsg38c@mailbox.rmplc.co.uk (TSG 38c)
- Newsgroups: comp.lang.c
- Subject: Re: directories listing
- Date: 15 Jan 1996 18:09:51 GMT
- Organization: RMPLC
- Message-ID: <4de59f$kdb@spider.rmplc.co.uk>
- References: <4dckfq$4um@news.ust.hk>
- Reply-To: tsg38c@rmplc.co.uk
- NNTP-Posting-Host: rmplcdyn-19.rmplc.co.uk
- X-Newsreader: WinVN 0.92.6+
-
- In article <4dckfq$4um@news.ust.hk>, cs_lcm@ug.cs.ust.hk (Lee Chun Man Raymond) says:
- >
- >
- >Hi,
- >
- > I wrote a C program that needs to print out a listing of
- >sub-directories of current working directory.
- >
- >The following is part of my program : ( Turbo C++ )
- >
- >struct find_t current_file;
- >int done;
- >.........
- >printf("Directories listing : \n");
- >done = _dos_findfirst(full_path , FA_DIREC, ¤t_file);
- >while (!done) {
- > strcpy(file_path, path_name);
- > strcat(file_path, "\\");
- > strcat(file_path, current_file.name)
- > printf("--> %s\n",file_path);
- > done = _dos_findnext(¤t_file);
- >}
- >
- >I don't know why it lists out all file including the sub-directories, but
- >I only want to lists our those sub-directories.
- >
- >Would someone help me?
- >
-
- The dos findfirst/findfirst commands finds all file matching the normal
- files attributes and the attribute you specify. If you change you program to
- the listing below it should work.
-
- printf("Directories listing : \n");
- done = _dos_findfirst(full_path , FA_DIREC, ¤t_file);
- while (!done) {
- if (current_file.attrib & FA_DIREC){
- strcpy(file_path, path_name);
- strcat(file_path, "\\");
- strcat(file_path, current_file.name)
- printf("--> %s\n",file_path);
- }
- done = _dos_findnext(¤t_file);
- }
-
-
-
- Gary.
-